package code.google.gui.adapter.util;

import java.util.Locale;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.support.v4.app.Fragment;
import code.google.gui.fragments.DummyFragment1;
import code.google.gui.fragments.search.LocalSearchFragment;
import code.google.gui.fragments.search.StreamSearchFragment;

import com.example.metamusicgui.R;

public class SearchContext extends MenuContext {
	
	private LocalSearchFragment local;
	private Fragment cloud;
	private StreamSearchFragment stream;
	private int itemIDLocal;
	private int itemIDCloud;
	private int itemIDStream;

	public SearchContext(Context context) {
		super(context);
		
		local = new LocalSearchFragment();
		cloud = new DummyFragment1();
		stream = new StreamSearchFragment();
		
		itemIDCloud = getItemID();
		itemIDLocal = getItemID();
		itemIDStream = getItemID();
		
//		setDummyData(local, "LOKAL");
		setDummyData(cloud, "CLOUD");
//		setDummyData(stream, "STREAM");
	}
	
	@Override
	public Fragment getItemHook(int position) {
		switch (position) {
		case 1:
			return local;
		case 2:
			return cloud;
		case 3:
			return stream;
			default:
				return null;
		}
		
	}

	@Override
	public int getCountHook() {
		return 3;
	}

	@Override
	public CharSequence getPageTitleHook(int position) {
		Locale l = Locale.getDefault();
		Resources res = context.getResources();
		switch (position) {
		case 1:
			return res.getString(R.string.title_local).toUpperCase(l);
		case 2:
			return res.getString(R.string.title_cloud).toUpperCase(l);
		case 3:
			return res.getString(R.string.title_stream).toUpperCase(l);
		}
		return null;
	}

	@Override
	public long getItemIDHook(int position) {
		switch (position) {
		case 1:
			return itemIDLocal;
		case 2:
			return itemIDCloud;
		case 3:
			return itemIDStream;
		}
		return -1;
	}

	@Override
	protected void onRegistrateFragmentsHook(Activity context) {
		local.registrateFragmentAt(context);
		stream.registrateFragmentAt(context);
	}

	@Override
	public void onDeregistrateFragmentsHook(Activity context) {
		local.deregistrateFragmentFrom(context);
		stream.deregistrateFragmentFrom(context);
	}

}
